<?php
/**
 * Created by PhpStorm.
 * User: yafex
 * Date: 2020/8/1
 * Time: 14:54
 */
class ctrl_wish_mq extends L {

    /**
     * 描述 : 获取店小秘订单明细
     * 作者 : Zoro.Zhu
     */
    public static function getOrderDetail($params = null){
//        $params['data'] = json_decode('{"orderState":"\u5df2\u53d1\u8d27","parcelNum":"XMKK39010332","orderId":"44128423648349412","pAccount":"\u300cWish\uff1ayangcaihong114112\u300d"}', true);
        $data = $params['data'];
        $sql = "SELECT
            orderData, dxmAccount, trackData
        FROM
            `dxm_order` 
        WHERE
            orderId = '{$data['orderId']}'";
        $order = L::sql($sql);
        if(empty($order)){
            return false;
        }
        $data = json_decode($order[0]['orderData'], true);
        $trackData = json_decode($order[0]['trackData'], true);
        //信息已经抓取，队列直接消费
//        if(isset($data['address']) && !empty($data['trackNo'])){
//            return true;
//        }
        $cookie = model_com::getAccountCookie($order[0]['dxmAccount']);
        $detail = serv_rep_dxm::getOrderDetail($cookie, $data['orderId']);
        //金额和时间
        $priceTime = serv_rep_dxm::getOrderPrice($cookie, $data['parcelNum'], $data['orderId']);
        //产品没抓到，队列先不结束
        if(empty($detail['productInfo'])){
            core_base::log(['params' => $params,'detail' => $detail, 'priceTime' => $priceTime], 'orderDetailError');
            return false;
        }
        foreach($detail['productInfo'] as $pOrderId => &$row){
            is_array($row) && !empty($priceTime[$pOrderId]) && is_array($priceTime[$pOrderId]) && $row += $priceTime[$pOrderId];
        }
        $detail += $data;
        $times = current($detail['productInfo']);
        $detail['shipTime'] = $times['shipTime'];
        $detail['createTime'] = $times['createTime'];
        $detail['submitTime'] = $times['submitTime'];
        $detail['paymentTime'] = $times['paymentTime'];
        $detail['printTime'] = !empty($times['printTime']) ? $times['printTime'] : '';
        if(!empty($detail['trackNo']) && (empty($trackData['status']) || !in_array($trackData['status'], ['delivered', 'expired']))){
            of_base_com_mq::set(['getTrackData', $data['orderId'], 60],['orderId' => $data['orderId'], 'trackNo' => $detail['trackNo']]);
        }
        $json = addslashes(json_encode($detail, JSON_UNESCAPED_UNICODE));
        L::sql("UPDATE `dxm_order` 
        SET `orderData` = '{$json}' 
        WHERE
            `orderId` = '{$data['orderId']}'");
        return true;
    }

    /**
     * 描述 : 计算利润
     * 作者 : Zoro.Zhu
     */
    public static function calProfits($params = null){
        $orderId = !empty($_GET['orderId']) ? $_GET['orderId'] : $params['data']['orderId'];
        $order = L::sql("SELECT
            orderId, orderData, wishUData, costPriceTotal, refund, aliData->>'$.baseInfo.totalAmount' as totalAmount
        FROM
            dxm_order 
        WHERE
            orderId = '{$orderId}'");
        $orderData = json_decode($order[0]['orderData'], true);
        $wishUData = json_decode($order[0]['wishUData'], true);
        $refund = json_decode($order[0]['refund'], true);
        if($order[0]['costPriceTotal'] <= 0 || empty($wishUData)){
            return true;
        }
        //首先看看有几个订单使用了同一个ali订单，需要均摊采购成本
        //均摊规则：采购总成本/使用了该采购订单的数量
        $qty = 1;
        if(!empty($orderData['pickingRemark'])){
            $qty = L::sql("SELECT
                count(0) as qty 
            FROM
                dxm_order 
            WHERE
                orderData ->> '$.pickingRemark' = '{$orderData['pickingRemark']}'");
            $qty = !empty($qty[0]['qty']) ? $qty[0]['qty'] : 1;
        }
        $currency = current($orderData['productInfo']);
        $currency = $currency['currency'];
        $usdCurrency = 1;
        $usdReturnCurrency = 1;
        $currency == 'USD' && $usdCurrency = 6.58; //美元兑人民币汇率
        !empty($refund['currency']) && $refund['currency'] == 'USD' && $usdReturnCurrency = 6.58; //美元兑人民币汇率
        //定义利润结构
        $profitsData = [
            'currency' => 'CNY',    //币种
            'salesPrice' => 0,     //销售额
            'freightRevenue' => 0,     //运费收入
            'platPrice' => 0, //平台交易费
            'costPrice' => 0,       //采购成本
            'shipFee' => 0, //发货物流运费
            'refundPrice' => 0, //退款金额
            'gross' => 0, //毛利
            'grossMargin' => 0, //毛利率（%）保留两位小数
            'costMargin' => 0, //成本利润率
        ];
        foreach($wishUData['payment_requests'] as $row){
            if($row['type'] == '退款'){
                $profitsData['shipFee'] -= $row['amount'];
            } else {
                $profitsData['shipFee'] += $row['amount'];
            }
        }
        //物流费为空，不计算利润
        if(empty($profitsData['shipFee'])){
            return true;
        }
        foreach($orderData['productInfo'] as $row){
            $profitsData['salesPrice'] += $row['price'] * $usdCurrency;
            $profitsData['freightRevenue'] += ($row['priceTotal'] - $row['price']) * $usdCurrency;
        }
        $profitsData['platPrice'] = ($profitsData['salesPrice'] + $profitsData['freightRevenue']) * 0.15; //wish平台收取百分之15的平台费
        $profitsData['costPrice'] = $order[0]['costPriceTotal'] == $order[0]['totalAmount'] ? $order[0]['costPriceTotal'] / $qty : $order[0]['costPriceTotal'];   //采购成本
        $profitsData['refundPrice'] = !empty($refund['price']) ? $refund['price'] * $usdReturnCurrency : 0;   //退款金额
        $profitsData['gross'] = round($profitsData['salesPrice'] + $profitsData['freightRevenue'] - $profitsData['platPrice'] - $profitsData['costPrice'] - $profitsData['shipFee'] - $profitsData['refundPrice'], 2);
        $profitsData['grossMargin'] = round($profitsData['gross'] / ($profitsData['salesPrice'] + $profitsData['freightRevenue']) * 100, 2);
        $profitsData['costMargin'] = round($profitsData['gross'] / ($profitsData['costPrice'] + $profitsData['shipFee']) * 100, 2);
        $profitsJson = addslashes(json_encode($profitsData));
        L::sql("UPDATE `dxm_order` 
        SET `profitsData` = '{$profitsJson}' 
        WHERE
            `orderId` = '{$orderId}'");
        return true;
    }

    /**
     * 描述 : 抓取物流节点信息
     * 作者 : Zoro.Zhu
     */
    public static function getTrackData($params = null){
        if(empty($params)){
            $_GET['json'] = str_replace('\\', '', $_GET['json']);
            $params['data'] = json_decode($_GET['json'], true);
        }
        $logistics = serv_rep_dxm::getTrackDog($params['data']['trackNo']);
        if(!empty($logistics['sendCountry'])){
            $json = addslashes(json_encode($logistics, JSON_UNESCAPED_UNICODE));
            L::sql("UPDATE `dxm_order` 
            SET `trackData` = '{$json}' 
            WHERE
                `orderId` = '{$params['data']['orderId']}'");
            return true;
        }
        return 600;
    }

    /**
     * 描述 : 买家视角收藏产品
     * 参数 : {
     *      productId : 产品ID
     *      account : 买家账号
     * }
     * 作者 : Zoro.Zhu
     */
    public static function buyAddProduct($params = null) {
        set_time_limit(0);
        $productId = !empty($params['data']['productId']) ? $params['data']['productId'] : $_GET['productId'];
        $account = !empty($params['data']['account']) ? $params['data']['account'] : $_GET['account'];
        $type = !empty($params['data']['type']) ? $params['data']['type'] : $_GET['type'];
        $token = model_wishBuyAccount::getParamsInfo(['account' => $account]);
        $data = $token[0] + ['productId' => $productId];
        $oper = L::sql("SELECT
            oper 
        FROM
            `wish_product` 
        WHERE
            id = '{$productId}'");
        $oper = !empty($oper[0]['oper']) ? json_decode($oper[0]['oper'], true) : [];
        //先浏览产品,并获取变种ID
        $variation = serv_rep_wish::lookProduct($data, true);
//        p($variation);
        //休息一会，然后收藏
        sleep(mt_rand(15, 60));
        //type 1只收藏 2只加入购物车
        if($type != 2){
            $res = serv_rep_wish::addProduct($data);
        }
        if(!empty($variation) && $type != 1){
            $variation = array_column($variation['staticFields']['commerceProductInfo']['variations'], 'variation_id');
            //休息一会，然后加入购物车
            sleep(mt_rand(15, 60));
            $key = array_rand($variation, 1);
            $data['variation_id'] = $variation[$key];
            $res2 = serv_rep_wish::addToCart($data);
        }
        L::sql(null);
        $info = L::sql("SELECT
            `data` 
        FROM
            `wish_favorites` 
        WHERE
            `productId` = '{$productId}'
        FOR UPDATE");
        $json = json_decode($info[0]['data'], true);
        $remark = $res === true ? (!empty($res2) ? '收藏成功并加入购物车' : '收藏成功') : $res;
        $res === true && $oper['addSaves'] = 1;
        $res2 === true && $oper['addCart'] = 1;
        $json['ok'][] = [
            'account' => $account,
            'date' => date('Y-m-d H:i:s'),
            'result' => $remark
        ];
        $sJson = addslashes(json_encode($json));
        $sql = "UPDATE `wish_favorites` 
        SET `data` = '{$sJson}' 
        WHERE
            `productId` = '{$productId}'";
        L::sql($sql);

        L::sql("INSERT INTO `wish_product_log`(
          `date`, `productId`, `remark`
        ) VALUES (
          '" . date('Y-m-d H:i:s') . "', '{$productId}', '{$remark}'
        )");
        $operJson = addslashes(json_encode($oper));
        L::sql("UPDATE `wish_product` 
        SET `oper` = '{$operJson}' 
        WHERE
            `id` = '{$productId}'");
        if(L::sql(true)){
            return true;
        }
    }

    /**
     * 描述 : 获取后台产品统计数据
     * 作者 : Zoro.Zhu
     */
    public static function getProductStats($params = null){
        $account = !empty($params['data']['account']) ? $params['data']['account'] : $_GET['account'];
        $id = !empty($params['data']['id']) ? $params['data']['id'] : $_GET['id'];
        $day = !empty($_GET['day']) ? $_GET['day'] : 22;
        $accountData = L::sql("SELECT
            cookie, xToken, state, merchantId 
        FROM
            `wish_seller_account` 
        WHERE
            `name` = '{$account}'");
        if(!empty($accountData[0]) && $accountData[0]['state'] == 1){
            $params = [
                'cookie' => $accountData[0]['cookie'],
                'xToken' => $accountData[0]['xToken'],
                'merchantId' => $accountData[0]['merchantId'],
                'id' => $id,
                'day' => $day,
            ];
            $res = serv_rep_wish::getProductStats($params);
            if($res === false){
                L::sql("UPDATE `wish_seller_account` SET `state` = 2 WHERE `name` = '{$account}'");
                return $day != 22 ? ['state' => 301, 'info' => 'Cookie已失效，请更新'] :true;
            }
            if(empty($res)){
                return $day != 22 ? ['state' => 302, 'info' => '更新完毕，无数据'] :true;
            }
            $data = [];
            foreach($res as $row){
                $date = date('Y-m-d', $row['timestamp']);
                $data[$date] = [
                    'date' => $date,
                    'feed_impression' => empty($row['feed_impression']) ? $row['feed_impression'] : $row['feed_impression'],
                    'impressions' => empty($row['impressions']) ? 0 : $row['impressions'],
                    'wishes' => empty($row['wishes']) ? 0 : $row['wishes'],             //收藏量
                    'num_sold' => empty($row['num_sold']) ? 0 : $row['num_sold'],             //扣库存数量
                    'add_to_cart' => empty($row['add_to_cart']) ? 0 : $row['add_to_cart'],       //添加到购物车
                    'total_m_txn_count' => empty($row['total_m_txn_count']) ? 0 : $row['total_m_txn_count'], //当日售出
                    'total_m_txn_cost' => empty($row['total_m_txn_cost']) ? 0 : $row['total_m_txn_cost'], //当日销售额（USD）
                    'daily_sum_ratings' => empty($row['daily_sum_ratings']) ? 0 : $row['daily_sum_ratings'],//当日总评分
                    'sum_ratings' => empty($row['sum_ratings']) ? 0 : $row['sum_ratings'], //总评分
                    'total_ratings' => empty($row['total_ratings']) ? 0 : $row['total_ratings'], //总评论数量
                    'rating_breakdown' => addslashes(json_encode($row['rating_breakdown'])), //评分细目
                    'refund_reasons_dict_count' => array_sum($row['refund_reasons_dict']), //当天退款数量
                    'refund_reasons_dict' => addslashes(json_encode($row['refund_reasons_dict'])), //当天退款细目
                ];
            }
            $sql = "INSERT INTO `wish_product_stats`(
                `id`, `date`, `feed_impression`, `impressions`, `wishes`, 
                `num_sold`, `add_to_cart`, `daily_sum_ratings`,  `refund_reasons_dict_count`, `refund_reasons_dict`,
                `total_m_txn_cost`, `total_m_txn_count`
            ) VALUES";
            foreach($data as $date => $row){
                $sql .= "('{$id}', '{$date}', '{$row['feed_impression']}', '{$row['impressions']}', '{$row['wishes']}', '{$row['num_sold']}', 
                '{$row['add_to_cart']}', '{$row['daily_sum_ratings']}', '{$row['refund_reasons_dict_count']}', '{$row['refund_reasons_dict']}',
                '{$row['total_m_txn_cost']}','{$row['total_m_txn_count']}'),";
            }
            L::sql(trim($sql, ',') . " ON DUPLICATE KEY UPDATE 
            `feed_impression` = VALUES(`feed_impression`),
            `impressions` = VALUES(`impressions`),
            `wishes` = VALUES(`wishes`),
            `num_sold` = VALUES(`num_sold`),
            `daily_sum_ratings` = VALUES(`daily_sum_ratings`),
            `refund_reasons_dict` = VALUES(`refund_reasons_dict`),
            `refund_reasons_dict_count` = VALUES(`refund_reasons_dict_count`),
            `total_m_txn_cost` = VALUES(`total_m_txn_cost`),
            `total_m_txn_count` = VALUES(`total_m_txn_count`),
            `add_to_cart` = VALUES(`add_to_cart`)");
            $info = L::sql("SELECT
                sum( impressions ) AS impressions,
                sum( feed_impression ) as feed_impression,
                sum( refund_reasons_dict_count ) AS refund_reasons_dict_count,
                sum( add_to_cart ) AS add_to_cart 
            FROM
                `wish_product_stats` 
            WHERE
                id = '{$id}'");
            L::sql("UPDATE wish_product 
            SET totalImpressions = '{$info[0]['impressions']}',
                totalFeedImpressions = '{$info[0]['feed_impression']}',
                sum_ratings = '{$row['sum_ratings']}',
                total_ratings = '{$row['total_ratings']}',
                rating_breakdown = '{$row['rating_breakdown']}',
                add_to_cart = '{$info[0]['add_to_cart']}',
                totalRefund = '{$info[0]['refund_reasons_dict_count']}' 
            WHERE
                id = '{$id}'");
            return $day != 22 ? ['state' => 200, 'info' => '更新了最近' . $day . '天数据，更新成功'] :true;
        }
        return $day != 22 ? ['state' => 303, 'info' => 'Cookie已失效，请更新'] :true;
    }

    /**
     * 描述 : 更新产品列表
     * 作者 : Zoro.Zhu
     */
    public static function getProduct($params = null) {
        set_time_limit(0);
        $day = !empty($_GET['day']) ? $_GET['day'] : $params['data']['day'];
        $account = !empty($_GET['account']) ? $_GET['account'] : $params['data']['account']; //"SELECT `name` FROM wish_seller_account WHERE state = 1"
        $account = L::sql("SELECT
          `account`, `appKey`, `appSecret`, `accessToken`, `refreshToken`,
          `invalidDate`, `state`, `type`, `addDate`
        FROM
          `vs_account` 
        WHERE `state` = '0'
        AND `type` = 'wish'
        AND account = '{$account}'");
        $data = [
            'limit' => 250, //最高250
            'start' => 0,
            'since' => date('Y-m-d', time() - 86400 * $day),
            'accessToken' => $account[0]['accessToken'],
        ];
        while (true) {
            $productData = [];
            $res = serv_rapi_wish::getProduct($data);
            if(!empty($res['data'])){
                $data['start'] += 250;
                foreach($res['data'] as $row){
                    $product = $row['Product'];
                    $date = explode("-", $product['date_uploaded']);
                    $date2 = explode("T", $product['last_updated']);
                    $date3 = explode("-", $date2[0]);
                    $tag = [];
                    if(!empty($product['tags'])){
                        foreach($product['tags'] as $t){
                            $tt = strtolower($t['Tag']['name']);
                            $tag[$tt] = $tt;
                        }
//                        of_base_com_mq::set(['getKeyword'],['keywords' => join(',', $tag)]);
                    }
                    $productData[$product['id']] = [
                        'id' => $product['id'],
                        'image' => $product['main_image'],
                        'name' => $product['name'],
                        'tag' => $tag,
                        'isPromoted' => $product['is_promoted'] === 'False' ? 0 : 1,
                        'removedByMerchant' => $product['removed_by_merchant'] === 'False' ? 0 : 1,
                        'reviewStatus' => $product['review_status'],
                        'parentSku' => $product['parent_sku'],
                        'dateUploaded' => $date[2] . '-' . $date[0] . '-' . $date[1] . ' 00:00:00', //date('Y-m-d H:i:s', strtotime($product['date_uploaded'])),
                        'lastUpdated' => $date3[2] . '-' . $date3[0] . '-' . $date3[1] . " {$date2[1]}",
                        'numberSaves' => $product['number_saves'],     //收藏数量
                        'numberSold' => $product['number_sold'],     //售出数量
                    ];
                    $skuData = [];
                    $rack = true;
                    foreach($product['variants'] as $sku){
                        $sku = $sku['Variant'];
                        $skuData[] = [
                            'sku' => $sku['sku'],
                            'localizedShipping' => $sku['localized_shipping'],
                            'localizedCurrencyCode' => $sku['localized_currency_code'],
                            'inventory' => $sku['inventory'],
                            'localizedPrice' => $sku['localized_price'],
                            'msrp' => $sku['msrp'],
                            'id' => $sku['id'],
                            'productId' => $sku['product_id'],
                            'size' => !empty($sku['size']) ? $sku['size'] : '',
                            'shippingTime' => $sku['shipping_time'],
                            'enabled' => $sku['enabled'],
                            'removedByWish' => $sku['removed_by_wish'],
                        ];
                        $sku['enabled'] == 'True' && $rack = false;
                    }
                    $productData[$product['id']]['detail'] = $skuData;
                    $rack && $productData[$product['id']]['removedByMerchant'] == 0 && $productData[$product['id']]['removedByMerchant'] = 1;
                }
                unset($res);
                $sql = "INSERT INTO `wish_product`(
                `id`, `account`, `uploadTime`, `updTime`, `parentSku`, `numberSaves`, `numberSold`, `data` , `reviewStatus`, `isPromoted`, `removedByMerchant`
                ) VALUES ";
                foreach ($productData as $id => $p){
                    $json = addslashes(json_encode($p));
                    $sql .= "(
                    '{$id}', '{$account[0]['account']}', '{$p['dateUploaded']}', '{$p['lastUpdated']}', '{$p['parentSku']}', {$p['numberSaves']}, {$p['numberSold']}, '{$json}', '{$p['reviewStatus']}', '{$p['isPromoted']}', '{$p['removedByMerchant']}'
                    ),";
                }
                L::sql(trim($sql, ',') . " ON DUPLICATE KEY UPDATE 
                `uploadTime` = VALUES(`uploadTime`),
                `numberSaves` = VALUES(`numberSaves`),
                `numberSold` = VALUES(`numberSold`),
                `reviewStatus` = VALUES(`reviewStatus`),
                `isPromoted` = VALUES(`isPromoted`),
                `removedByMerchant` = VALUES(`removedByMerchant`),
                `data` = VALUES(`data`),
                `updTime` = VALUES(`updTime`)");
            }else{
                break;
            }
        }
        //获取统计数据
        if(!empty($params['data']['getProductStats'])){
            $sql = "SELECT
                id, account 
            FROM
                `wish_product` 
            WHERE
                account = '{$params['data']['account']}'";
            $product = L::sql($sql);
            $sql = "INSERT INTO `_of_com_mq`(`mark`, `vHost`, `queue`, `type`, `msgId`, `data`, `syncCount`, `updateTime`, `createTime`, `syncLevel`, `lockTime`, `lockMark`) VALUES";
            $date = date('Y-m-d H:i:s');
            foreach ($product as $row) {
                $json = addslashes(json_encode($row));
                $sql .= "('{$row['id']}', '', 'vs', 'getProductStats', '{$row['id']}', '{$json}', 0, '{$date}', '{$date}', 0, '{$date}', ''),";
            }
            L::sql(trim($sql, ',') . " ON DUPLICATE KEY UPDATE 
            `data` = VALUES(`data`)");
        }
        return true;
    }


    /**
     * 描述 : 获取关键词热度和竞争力
     * 作者 : Zoro.Zhu
     */
    public static function getKeyword($params = null){
        $keywords = !empty($_GET['k']) ? $_GET['k'] : $params['data']['keywords'];
        $accountData = L::sql("SELECT
            cookie, xToken, state, merchantId, `name`
        FROM
            `wish_seller_account` 
        WHERE
            `state` = '1'
        ORDER BY rand() LIMIT 1");
        $data = [
            'cookie' => $accountData[0]['cookie'],
            'xToken' => $accountData[0]['xToken'],
            'keywords' => $keywords,
        ];
        $res = serv_rep_wish::getKeyword($data);
        if(!empty($res)){
            $date = date('Y-m-d H:i:s');
            $insertSql = "INSERT INTO `wish_product_keyword`(
              `keyword`, `competition_level`, `reach_level`, `high_bid`, `reach_style`, 
              `upd_time`, `amount`, `avgFreightPrice`, `avgWishPrice`, `itemAmount`, 
              `itemCount`, `itemCountRate`, `rateNum`, `rateNum7`, `rateNum7Rate`
            ) VALUES ";
            foreach($res as &$row){
                $row['keyword'] = trim($row['keyword']);
                empty($row['reach_style']) && $row['reach_style'] = '';
                $tagTmw = serv_rep_taomaiwang::getKeyword($row['keyword']);
                !empty($tagTmw[$row['keyword']]) ? $row += $tagTmw[$row['keyword']] : $row += [
                    'amount' => 0,
                    'avgFreightPrice' => 0,
                    'avgWishPrice' => 0,
                    'itemAmount' => 0,
                    'itemAmountRate' => 0,
                    'itemCount' => 0,
                    'itemCountRate' => 0,
                    'rateNum' => 0,
                    'rateNum7' => 0,
                    'rateNum7Rate' => 0,
                ];
                $insertSql .= " ('" . addslashes($row['keyword']) . "', '{$row['competition_level']}', '{$row['reach_level']}', '{$row['high_bid']}', '{$row['reach_style']}',
                 '{$date}', '{$row['amount']}', '{$row['avgFreightPrice']}', '{$row['avgWishPrice']}', '{$row['itemAmount']}', 
                 '{$row['itemCount']}', '{$row['itemCountRate']}', '{$row['rateNum']}', '{$row['rateNum7']}', '{$row['rateNum7Rate']}'),";
            }
            L::sql(trim($insertSql, ',') . " ON DUPLICATE KEY UPDATE 
            `competition_level` = VALUES(`competition_level`),
            `reach_level` = VALUES(`reach_level`),
            `high_bid` = VALUES(`high_bid`),
            `reach_style` = VALUES(`reach_style`),
            `amount` = VALUES(`amount`),
            `avgFreightPrice` = VALUES(`avgFreightPrice`),
            `avgWishPrice` = VALUES(`avgWishPrice`),
            `itemAmount` = VALUES(`itemAmount`),
            `itemCount` = VALUES(`itemCount`),
            `itemCountRate` = VALUES(`itemCountRate`),
            `rateNum` = VALUES(`rateNum`),
            `rateNum7` = VALUES(`rateNum7`),
            `rateNum7Rate` = VALUES(`rateNum7Rate`),
            `upd_time` = VALUES(`upd_time`)");
            return !empty($params['data']['look']) ? $res : true;
        } else if($res === false) {
            L::sql("UPDATE `wish_seller_account` SET `state` = 2 WHERE `name` = '{$accountData[0]['name']}'");
            return false;
        }
        return false;
    }

}
return true;